<template>
	<view class="page">
		<u-navbar title="账号安全" autoBack fixed placeholder titleStyle="color: #232832" leftIconColor="#232832"
			bgColor="#FFFFFF"></u-navbar>
		<c-content :top="statusBarHeight + 44" bgColor="#F4F4F7">
			<u-gap height="10px" bgColor="transparent"></u-gap>
			<view class="cell" v-for="(menu, i) in menus" :key="i">
				<view class="cell-item__icon">
					<text :class="menu.icon"></text>
				</view>
				<view class="cell-item__title">{{ menu.title }}</view>
				<view class="cell-item__value">
					<u-icon v-if="menu.valueType == 'icon'" name="arrow-right" color="#232832"></u-icon>
					<u-switch v-model="menu.value" :size="20" v-else-if="menu.valueType == 'switch'"
						@change="switchChange($event, menu)"></u-switch>
					<text v-else-if="menu.valueType == 'value'">{{ menu.value }}</text>
				</view>
			</view>
		</c-content>
	</view>
</template>

<script>
	import mixins from '@/mixins/index.js'
	export default {
		mixins: [mixins],
		data() {
			return {
				menus: [{
						icon: 'icon-notice',
						title: '新消息提醒',
						valueType: 'switch',
						value: false,
						url: ''
					},
					{
						icon: 'icon-thumb',
						title: '点赞',
						valueType: 'switch',
						value: false,
						url: ''
					},
					{
						icon: 'icon-comment',
						title: '评论',
						valueType: 'switch',
						value: false,
						url: ''
					},
					{
						icon: 'icon-attention',
						title: '关注',
						valueType: 'switch',
						value: false,
						url: ''
					},
				]
			}
		},
		onShow() {
			uni.getStorage({
				key: 'notice',
				complete: (rs) => {
					JSON.parse(rs.data).forEach((el, index) => {
						if (rs.data) {
							this.$set(this.menus[1].children[index], 'value', el.value)
						}
					})
				}
			})
		},
		methods: {
			switchChange(val, menu) {
				console.log(val, menu);
				uni.setStorage({
					key: 'notice',
					data: JSON.stringify(this.menus[1].children)
				})
			},
		}
	}
</script>

<style scoped lang="scss">
	.cell {
		display: flex;
		align-items: center;
		background-color: #FFFFFF;
		padding: 10px 22px;
		border-bottom: 1px solid #F4F4F7;

		&-item__icon {
			margin-right: 13px;
			color: #232832;
		}

		&-item__title {
			flex: 1;
			color: #232832;
			font-size: 15px;
			line-height: 23px;
			font-weight: 400;
		}

		&-item__value {
			color: #666666;
			font-size: 13px;
			line-height: 18px;
			font-weight: 400;
		}
	}
</style>